<?php 
/**
 * 品牌管理控制器
 */
class BrandController extends AuthController{
	private $model;
	public function __init(){
		parent::__init();
		$this->model = K('Brand');
		
	}
	
	/**
	 * 首页列表
	 */
	public function index(){
		$data = $this->model->order("bsort ASC")->all();
		$this->assign('data',$data);
		
		$this->display();
	}
	
	/**
	 * 品牌添加
	 */
	public function add(){
		
		if(IS_POST){
			if(!$this->model->addBrand()) $this->error($this->model->error);
			$this->success('添加成功');
		}
		
		$this->display();
	}
	
	/**
	 * 品牌编辑
	 */
	public function edit(){
		//获取bid
		$bid = Q('get.bid',0,'intval');
		//获取所有分配旧数据
		$oldData = $this->model->where("bid={$bid}")->find();
		$this->assign('oldData',$oldData);
		
		if(IS_POST){
			if(!$this->model->edit($bid)) $this->error($this->model->error);
			$this->success('修改成功',U('index'));
		}
		
		$this->display();
	}
	
	/**
	 * 商品删除
	 */
	public function del(){
		//获取bid
		$bid = Q('get.bid',0,'intval');
		$this->model->where("bid={$bid}")->delete();
		$this->success('删除成功');
		
	}
}





















 ?>